const HtmlPlugin = require('html-webpack-plugin')
const htmlPlugin = new HtmlPlugin({
  template: './src/index.html',      //指定原生文件的存放路径
  filename: './index.html',            //指定生成文件的存放路径
})

const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const cleanPlugin = new CleanWebpackPlugin()

module.exports = {
  mode: 'development',
  devtool: 'eval-source-map',
  entry: './src/index.js',
  output: {
    filename: 'js/bundle.js', path: __dirname + '/dist',
  },
  devServer: {
    static: {
      directory: __dirname + '/',
    },
    port: 8080,
  },
  plugins: [htmlPlugin, cleanPlugin],
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.less$/i,
        use: ["style-loader", "css-loader", "less-loader"],
      },
      {
        test: /\.(png|svg|jpg|gif)$/i,
        type: "asset",
        parser: {
          dataUrlCondition: {
            maxSize: 33655
          }
        }
      },
      {
        test: /\.js$/i,
        // 排除项 
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: [
              ["@babel/preset-env"]
            ]
          }
        }
      },
      {
        test: /\.(png|svg|jpg|gif)$/i,
        type: "asset",
        generator: {
          filename: "img/[name]_[hash:6][ext]"
        }, parser: {
          dataUrlCondition: {
            maxSize: 33655
          }
        }
      },
    ],
  },
};